/* SpriteBank.java
 * Created on 15-May-2006 by Jordan at 5:48:49 PM
 */

package mduel;

import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.HashMap;

import javax.imageio.ImageIO;

public class SpriteBank extends HashMap{
	private static final long serialVersionUID = 1L;
    
    public SpriteBank() {
        super();
        
    }
    /** @deprecated Replace by loading images using loadAllImages and retrieveImage
     */
    @SuppressWarnings("unchecked")
    @Deprecated
    public BufferedImage loadImage(String resource) {
    if (get(resource) != null)
        return (BufferedImage) get(resource);
		try {
        
			BufferedImage image = ImageIO
					.read(getClass().getClassLoader().getResource(resource));
            put(resource, image);
			return image;
		} catch (java.io.IOException ioe) {
			System.err.println("Image Load Error: " + ioe);
			return null;
		}
	}
    @SuppressWarnings("unchecked")
    public void loadAllImages(String[] src, String[] res_name)
        {
        if(src.length == res_name.length)
            {
            System.out.println("Loading Graphics... ");
            for(int i = 0; i <= (src.length-1); i++)
                {
                try {
                
                System.out.println(getClass().getClassLoader().getResource(src[i]));
                    BufferedImage image = ImageIO
                            .read(getClass().getClassLoader().getResource(src[i]));
                    put(res_name[i], image);
                    }
                catch (java.io.IOException ioe) {
                    System.err.println("Image Load Error: " + ioe);
                    }
                }
            System.out.println("...Done.");
            }
        else
            {
            throw new IllegalArgumentException("Array Length Mismatch");
            }
        }
    public BufferedImage retrieveImage(String imageName)
        {
        if (get(imageName) != null)
            return (BufferedImage) get(imageName);
        else return null;
        }

	public static InputStream getFile(String resource, Object Parent) {
		try {
			return Parent.getClass().getClassLoader().getResourceAsStream(
					resource);
		} catch (Exception e) {
			System.err.println("File Load Error: " + e);
			return null;
		}
	}

	public static Font getFont_from_file(String resource, Object Parent) {
		try {
			return Font.createFont(Font.TRUETYPE_FONT, SpriteBank.getFile(
					"marshmallowDuel.ttf", Parent));
		} 
        catch (Exception e) {
			System.err.println("Font Creation Error: " + e);
			return null;
		}

	}
}